namespace Cmpp.Client.Cmpp3Message.Utility {
    internal class InterlockedCounter {
        private static readonly object lockedObject;

        static InterlockedCounter() {
            lockedObject = new object();
        }

        public static uint Add(ref uint value, uint variable) {
            lock (lockedObject) {
                value = unchecked(value + variable);
                return value;
            }
        }

        public static uint Increment(ref uint value) {
            return Add(ref value, 1);
        }

        public static uint Decrement(ref uint value) {
            lock (lockedObject) {
                value = unchecked(value - 1);
                return value;
            }
        }
    }
}